<!--
 * @Author: bear
 * @Date: 2022-08-05 13:59:43
 * @LastEditors: bear
 * @LastEditTime: 2022-08-05 15:07:01
 * @Description: your project
 * @version: 1.0
-->
<template>
  <div class="eventEmitter">
    <span @click="clickEventEmitter">点击入门异步事件驱动</span>
    <br />
    <span @click="clickMoreEventEmitter">点击入门异步事件驱动(链式调用)</span>
  </div>
</template>
<script setup>
const { EventEmitter } = require("events");

const eventEmitter = new EventEmitter();
// first
// 添加事件回调
eventEmitter.on("say", () => {
  console.log("say hello");
});

const clickEventEmitter = () => {
  setTimeout(() => {
    eventEmitter.emit("say");
  }, 1000);
  console.log("执行结束！");
};
// two
eventEmitter
  .on("say1", () => {
    console.log(1);
  })
  .on("say1", () => {
    console.log(2);
  });
const clickMoreEventEmitter = () => {
  eventEmitter.emit("say1");
};
</script>
<style scoped></style>
